<template>
  <div class="page-containers">
    <!--工具栏-->
    <div class="toolbar">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-row class="search-input">
          <el-row class="times">
          <el-form-item label="成长值变动时间：">
            <el-date-picker v-model="filters.startTime" type="datetime" placeholder="开始时间"  @change="changeStartDate"
                :picker-options="startDateDisabled"  class="input_postion" clearable></el-date-picker>
            <span class="times-to">-</span>
            <el-date-picker v-model="filters.endTime" type="datetime" placeholder="结束时间" class="input_postion"
                clearable
                @change="changeEndDate"
                :picker-options="endDateDisabled"></el-date-picker>
          </el-form-item>
          </el-row>
          <el-form-item label="变动方式：" label-width="128px">
            <el-select v-model="filters.changeType" placeholder="全部">
              <el-option label="参与平台活动  " value="9"></el-option>
              <el-option label="发布活动" value="10"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="变动类型：" label-width="128px">
            <el-select v-model="filters.addOrReduce" placeholder="全部">
              <el-option label="成长值获取" value="1"></el-option>
              <el-option label="成长值消耗" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-row>

        <div class="search-button-noborder">
          <el-form-item class="noMargin">
            <el-button @click="resetForm('filters')" class="resetButton" icon="el-icon-refresh">重置</el-button>
          </el-form-item>
          <el-form-item class="noMargin">
            <kt-button icon="el-icon-search" class="searchButton" :label="'搜索'"  @click="findPage(null)" />
          </el-form-item>
        </div>
      </el-form>
    </div>
    <div class="toolbar">
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :loading="loading"
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      @findPage="findPage"
      @selectionChange="selectionChange"
      :showBatchDelete="false"
      showDetailOperation
      :showDeleteOperation="false"
      :showPushOperation="false"
      :showOperation="false"
      :showSelection="false"
      ref="CyTable"
    ></cy-table>
  </div>
</template>

<script>
import { exportExcel } from "@/utils/excel";
import CyTable from "@/views/Core/JicTable";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import {
  validatePhone,
  validateContacts,
  isEmail,
  isNumber
} from "@/utils/validate";
import XLSX from "xlsx";
export default {
  props: ["memberId"],
  components: {
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      startTime: null,
      endTime: null,
      loading: false, // 加载标识
      id: this.$route.params.id,
      //thirdUserId:this.$route.params.id,
      businessId: "",
      deptMsg: localStorage.getItem("user"), //当前登录组织信息
      userId: localStorage.getItem("userId"), //当前登录用户id
      deptType: localStorage.getItem("deptType"), //当前登录用户所属组织类型
      createTime: null,
      changeMode: null,
      changeTypes: null,
      integralType: null,
      deptName: null,
      deptOption: [],
      content: null,
      size: "small",
      filters: {
        storeMember: 1
      },
      columns: [
        {
          prop: "changeType",
          label: "成长值变动方式",
          minWidth: 130,
          formatter: this.changeModeFormatter
        },
        {
          prop: "addOrReduce",
          label: "变动类型",
          minWidth: 120,
          formatter: this.changeTypesFormatter
        },
        {
          prop: "growthRuleVal",
          label: "变动成长值",
          minWidth: 120,
          formatter: this.growthRuleValFormatter
        },
        { prop: "growthNumber", label: "成长值余额", minWidth: 120 },
        { prop: "createTime", label: "成长值变动时间", minWidth: 120 }
      ],
      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},
      value: 0,
      printPage: false,
      editLoading: false,
      reviewFormRules: {},
      checked: [],
      statusList: [],
       startDateDisabled: {}, //开始时间限制
      endDateDisabled: {} //结束时间限制
    };
  },
  methods: {
    changeStartDate: function() {
      var this_ = this;
      this_.endDateDisabled = {
        disabledDate: time => {
          if (this_.filters.startTime) {
            return (
              time.getTime() <= new Date(this_.filters.startTime).getTime()
            );
          }
        }
      };
    },
    changeEndDate: function() {
      var this_ = this;
      this_.startDateDisabled = {
        disabledDate: time => {
          if (this_.filters.endTime) {
            return time.getTime() >= new Date(this_.filters.endTime).getTime();
          }
        }
      };
    },
    // 获取分页数据
    findPage: function(data) {
      if (this.memberId == undefined) {
        return;
      }
      this.loading = true;
      if (data != null && data.start != null) {
        if (data.start != null) {
          this.pageRequest.pageNum = data.start;
        }
        if (data.limit != null) {
          this.pageRequest.pageSize = data.limit;
        }
      }
      let this_ = this;
      if (this_.filters == undefined || this_.filters == null) {
        this_.filters = {};
      }
      this_.filters.start = this.pageRequest.pageNum;
      this_.filters.limit = this.pageRequest.pageSize;
      this_.filters.memberId = this_.memberId;
      this.utils.request.getMemberLogList(this_.filters, function(res) {
        this_.loading = false;
        if (res.data == null) {
          res.data = [];
          res.totle = 0;
        } else {
          this_.$refs.CyTable.findPage({
            content: res.data.rows,
            total: res.data.total
          });
        }
      });
    },

    growthRuleValFormatter: function(row, column, cellValue, index) {
      if (row.integralType == 1) {
        return "-" + cellValue;
      } else {
        return "+" + cellValue;
      }
    },

    integralTypeFormatter: function(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "消费积分";
      } else if (cellValue == 2) {
        return "任务积分";
      } else if (cellValue == 3) {
        return "活动积分";
      }
    },

    changeTypesFormatter: function(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "成长值获取";
      } else if (cellValue == 2) {
        return " 成长值消耗";
      }
    },

    changeModeFormatter: function(row, column, cellValue, index) {
      if (cellValue == 1) {
        return "下单赠送";
      } else if (cellValue == 2) {
        return " 注册赠送";
      } else if (cellValue == 3) {
        return " 评价赠送";
      } else if (cellValue == 4) {
        return " 充值赠送";
      } else if (cellValue == 5) {
        return " 分享赠送";
      } else if (cellValue == 6) {
        return " 点赞赠送";
      } else if (cellValue == 7) {
        return " 晒单赠送";
      } else if (cellValue == 8) {
        return " 收藏赠送";
      } else if (cellValue == 8) {
        return " 收藏赠送";
      } else if (cellValue == 8) {
        return " 收藏赠送";
      } else if (cellValue == 9) {
        return " 参与平台活动";
      } else if (cellValue == 10) {
        return " 发布活动";
      } else if (cellValue == 11) {
        return " 兑换优惠券";
      } else if (cellValue == 12) {
        return " 兑换红包";
      } else if (cellValue == 13) {
        return " 兑换产品功能";
      } else if (cellValue == 14) {
        return " 兑换付费内容";
      } else if (cellValue == 15) {
        return " 退款返还";
      } else if (cellValue == 16) {
        return " 取消评价返还";
      } else if (cellValue == 17) {
        return " 取消点赞返还";
      } else if (cellValue == 18) {
        return " 兑换抽奖活动";
      }
    },
    //获取子平台列表
    queryDeptOption() {
      let query = {};
      let this_ = this;
      this_.utils.request.queryChildList(query, function(res) {
        if (res.code == "0000") {
          this_.deptOption = res.data;
        }
      });
    },
    //获取选择框数据
    selectionChange(val) {
      this.checked = val.selections;
    },

    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },

    resetForm(formName) {
      this.filters = { storeMember: 1 };
      this.findPage(null);
    },

    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];
      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    }
  },
  mounted() {
    this.initColumns();
    // this.findPage()
    this.queryDeptOption();
    this.timer = setTimeout(() => {
      //设置延迟执行
      this.findPage();
    }, 200);
  }
};
</script>

<style lang="scss" scoped>
.reset {
  background-color: #fff;
  color: #409eff;
}
.noMargin {
  margin-right: 0 !important;
  margin-bottom: 0 !important;
}
</style>
